package com.jrsoft.bim.util.paser;

import com.jrsoft.bim.db.DBV2Util;
import com.jrsoft.bim.dto.excel.ComponentDTO;
import com.jrsoft.bim.dto.excel.FieldDTO;
import com.jrsoft.bim.enums.ComponentCategoryEnum;
import com.jrsoft.bim.util.MathUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ${DESCRIPTION}
 *
 * @author Blueeyedboy
 * @create 2020-07-18 9:50 AM
 **/
public class WallParse extends AbstractComponentParse {
	@Override
	public void parse(List<ComponentDTO> wallList, DBV2Util dbUtil) {
		if(wallList != null) {
			int index = 0;
			for (ComponentDTO c : wallList) {
				c.setId(++index);
				Map<String, FieldDTO> fields = c.getFieldDTOMap();
				FieldDTO kl50 = c.getFieldDTOMap().get("KL50");
				int n = MathUtil.getIntegerValue(kl50);
				Map<String, Object> params = new HashMap<>(10);
				Object value;
				// 水平筋
				String expression = "( "
						+ "XQS23^2*pai/4*(XQS10/XQS24) * ( XQS01+JQZ25+XQS56-JQZ12*2+(0.6*40*XQS23+15*XQS23)*2 )"
						+ "+YQS23^2*pai/4*(YQS10/YQS24) * ( YQS01+JQZ26+YSQ56-JQZ12*2+(0.6*40*YQS23+15*YQS23)*2 )"
						+ ")*2*7.85/1000/1000";
				params.clear();
				params.put("XQS23",MathUtil.getNumStringValue(fields.get("XQS23")));
				params.put("XQS10",MathUtil.getNumStringValue(fields.get("XQS10")));
				params.put("XQS24",MathUtil.getNumStringNotZero(fields.get("XQS24")));
				params.put("XQS01",MathUtil.getNumStringValue(fields.get("XQS01")));
				params.put("JQZ25",MathUtil.getNumStringValue(fields.get("JQZ25")));
				params.put("XQS56",MathUtil.getNumStringValue(fields.get("XQS56")));
				params.put("JQZ12",MathUtil.getNumStringValue(fields.get("JQZ12")));
				params.put("XQS23",MathUtil.getNumStringValue(fields.get("XQS23")));

				params.put("YQS23",MathUtil.getNumStringValue(fields.get("YQS23")));
				params.put("YQS10",MathUtil.getNumStringValue(fields.get("YQS10")));
				params.put("YQS24",MathUtil.getNumStringNotZero(fields.get("YQS24")));
				params.put("YQS01",MathUtil.getNumStringValue(fields.get("YQS01")));
				params.put("JQZ26",MathUtil.getNumStringValue(fields.get("JQZ26")));
				params.put("YSQ56",MathUtil.getNumStringValue(fields.get("YSQ56")));
				params.put("YQS23",MathUtil.getNumStringValue(fields.get("YQS23")));
				params.put("pai", PAI_STR);

				value = MathUtil.evaluate(expression, params);
				System.out.println("----水平筋----o2-----"+value);
				c.setV1(MathUtil.getDoubleValue(value));

				// 纵筋:
				Object subValue1 = null;
				String subExpression1 = "YQS21^2*pai/4*YQS10 * (YQS01/YQS22)*2";
				expression = "( XQS21^2*pai/4*XQS10 * (XQS01/XQS22)*2"
						+ "+ subValue1 "
						+ ")*7.85/1000/1000";
				params.clear();
				String yqs22 = MathUtil.getNumStringValue(fields.get("YQS22"));
				params.put("XQS21",MathUtil.getNumStringValue(fields.get("XQS21")));
				params.put("XQS10",MathUtil.getNumStringValue(fields.get("XQS10")));
				params.put("XQS01",MathUtil.getNumStringValue(fields.get("XQS01")));
				params.put("XQS22",MathUtil.getNumStringNotZero(fields.get("XQS22")));
				params.put("YQS21",MathUtil.getNumStringValue(fields.get("YQS21")));
				params.put("YQS10",MathUtil.getNumStringValue(fields.get("YQS10")));
				params.put("YQS01",MathUtil.getNumStringValue(fields.get("YQS01")));
				params.put("YQS22",MathUtil.getNumStringNotZero(fields.get("YQS22")));
				params.put("pai", PAI_STR);

				if(Double.parseDouble(yqs22) == 0){
					subValue1 = "0";
				}else{
					subValue1 = MathUtil.evaluate(subExpression1, params);
				}

				params.put("subValue1", subValue1);
				value = MathUtil.evaluate(expression, params);
				System.out.println("----纵筋----o2-----"+value);
				c.setV2(MathUtil.getDoubleValue(value));

				// 拉筋
				expression = "( "
						+ "  XQS26^2*pai/4*(XQS01/XQS27) *(XQS10/XQS27) * ( XQS02-JQZ12*2+ 10*XQS26)"
						+ "+ YQS26^2*pai/4*(YQS01/YQS27) *(YQS10/YQS27) * ( YQS02-JQZ12*2+ 10*YQS26)"
						+ ")*7.85/1000/1000";
				params.clear();
				params.put("XQS26",MathUtil.getNumStringValue(fields.get("XQS26")));
				params.put("XQS01",MathUtil.getNumStringValue(fields.get("XQS01")));
				params.put("XQS27",MathUtil.getNumStringNotZero(fields.get("XQS27")));
				params.put("XQS10",MathUtil.getNumStringValue(fields.get("XQS10")));
				params.put("XQS02",MathUtil.getNumStringValue(fields.get("XQS02")));
				params.put("JQZ12",MathUtil.getNumStringValue(fields.get("JQZ12")));

				params.put("YQS26",MathUtil.getNumStringValue(fields.get("YQS26")));
				params.put("YQS01",MathUtil.getNumStringValue(fields.get("YQS01")));
				params.put("YQS27",MathUtil.getNumStringNotZero(fields.get("YQS27")));
				params.put("YQS10",MathUtil.getNumStringValue(fields.get("YQS10")));
				params.put("YQS02",MathUtil.getNumStringValue(fields.get("YQS02")));
				params.put("pai", PAI_STR);

				value = MathUtil.evaluate(expression, params);
				System.out.println("----拉筋----o3-----"+value);
				c.setV3(MathUtil.getDoubleValue(value));


				// 先插入梁组件
				c.setCategoryEnum(ComponentCategoryEnum.WALL);
				dbUtil.insertWall(c);

			}
		}
	}
}
